package org.xiaoyu.rpc.registry.zookeeper;

import org.xiaoyu.rpc.registry.Registry;
import org.xiaoyu.rpc.registry.RegistryFactory;

import java.util.Properties;

/**
 * Created By Have
 * 2021/7/14 22:55
 */
public class ZookeeperRegistrySingletonFactory implements RegistryFactory {
    private volatile Registry registry;

    @Override
    public Registry createRegistry(Properties properties) {
        if (registry == null) {
            synchronized (this) {
                if (registry == null) {
                    ZookeeperInstanceWrapper zookeeperInstanceWrapper = new ZookeeperInstanceWrapper(properties);
                    registry = new ZookeeperRegistry(zookeeperInstanceWrapper);
                }
            }
        }
        return registry;
    }
}
